<?php


namespace app\admin\controller;


use app\admin\model\MessageSystem as MessageSystemModel;
use app\admin\model\Notice as NoticeModel;
use app\common\controller\AdminController;
use think\Exception;
use think\facade\Request;

/**
 * 系统消息
 * Class MessageAgentSystem
 * @package app\admin\controller
 */
class MessageSystem extends AdminController {

    public $resubmitLock = ['add', 'edit'];

    public $levelConfig = [
        1 => ['getlist','addget','editget'],
        2 => ['addpost', 'del', 'editpost'],
        4 => [],
        8 => []
    ];

    /**
     * 列表
     * @return false|string
     */
    public function getList() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $list = MessageSystemModel::getList($params);
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 新增获取
     * @return false|string
     */
    public function addGet() {
        try {
            $list = [
                ['key' => 1, 'value' => 'app内开'],
                ['key' => 2, 'value' => 'h5网页']
            ];
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 新增提交
     * @return false|string
     */
    public function addPost() {
        try {
            $params = $this->checkParams('title,content');
            if ($params === false) return $this->resErr();
            $res = MessageSystemModel::post($params);
            if (!$res) return $this->resErr();
            else return $this->resData('添加成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑获取
     * @return false|string
     */
    public function editGet() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $res1 = MessageSystemModel::info($params['id'], $info);
            if (!$res1) return $this->resErr();
            else $res['info'] = $info;
            $res['list'] = [
                ['key' => 1, 'value' => 'app内开'],
                ['key' => 2, 'value' => 'h5网页']
            ];
            return $this->resData('success', $res);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑提交
     * @return false|string
     */
    public function editPost() {
        try {
            $params = $this->checkParams('title,content,id');
            if ($params === false) return $this->resErr();
            $res = MessageSystemModel::post($params);
            if (!$res) return $this->resErr();
            else return $this->resData('操作成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 删除
     * @return false|string
     */
    public function del() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $res = MessageSystemModel::del($params);
            if (!$res) return $this->resErr();
            else return $this->resData('操作成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }


}
